package lp.xian.equipment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import lp.xian.equipment.vo.SalaryVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import lp.xian.equipment.domain.Salary;
import lp.xian.equipment.service.ISalaryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工资Controller
 *
 * @author ruoyi
 * @date 2023-07-21
 */
@RestController
@RequestMapping("/salary/salary")
public class SalaryController extends BaseController
{
    @Autowired
    private ISalaryService salaryService;

    /**
     * 修改工资
     */
    @PreAuthorize("@ss.hasPermi('salary:salary:audit')")
    @Log(title = "工资", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult auditSalary(@RequestBody SalaryVo salaryvo)
    {
        return toAjax(salaryService.auditSalary(salaryvo));
    }

    /**
     * 查询工资列表
     */
    @PreAuthorize("@ss.hasPermi('salary:salary:list')")
    @GetMapping("/list")
    public TableDataInfo list(Salary salary)
    {
        startPage();
        List<Salary> list = salaryService.selectSalaryList(salary);
        return getDataTable(list);
    }

    /**
     * 导出工资列表
     */
    @PreAuthorize("@ss.hasPermi('salary:salary:export')")
    @Log(title = "工资", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Salary salary)
    {
        List<Salary> list = salaryService.selectSalaryList(salary);
        ExcelUtil<Salary> util = new ExcelUtil<Salary>(Salary.class);
        util.exportExcel(response, list, "工资数据");
    }

    /**
     * 获取工资详细信息
     */
    @PreAuthorize("@ss.hasPermi('salary:salary:query')")
    @GetMapping(value = "/{salaryId}")
    public AjaxResult getInfo(@PathVariable("salaryId") Integer salaryId)
    {
        return success(salaryService.selectSalaryBySalaryId(salaryId));
    }

    /**
     * 新增工资
     */
    @PreAuthorize("@ss.hasPermi('salary:salary:add')")
    @Log(title = "工资", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Salary salary)
    {
        return toAjax(salaryService.insertSalary(salary));
    }

    /**
     * 修改工资
     */
    @PreAuthorize("@ss.hasPermi('salary:salary:edit')")
    @Log(title = "工资", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Salary salary)
    {
        return toAjax(salaryService.updateSalary(salary));
    }

    /**
     * 删除工资
     */
    @PreAuthorize("@ss.hasPermi('salary:salary:remove')")
    @Log(title = "工资", businessType = BusinessType.DELETE)
    @DeleteMapping("/{salaryIds}")
    public AjaxResult remove(@PathVariable Integer[] salaryIds)
    {
        return toAjax(salaryService.deleteSalaryBySalaryIds(salaryIds));
    }
}
